<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        body {
            margin-top: 100px;
            background: url('https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_1280.jpg') no-repeat;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md4 layui-col-md-offset4">
            <div class="layui-card ">
                <div class="layui-card-header">用户注册</div>
                <div class="layui-card-body">
                    <form id="form1" class="layui-form" action="">
                        <!--                        enctype="multipart/form-data"-->
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i>用户名</label>
                            <div class="layui-input-inline">
                                <input id="username" type="text" name="name" required lay-verify="required"
                                       placeholder="请输入标题"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i>密码框</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" required lay-verify="required"
                                       placeholder="请输入密码"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-user"></i>性&nbsp;&nbsp;&nbsp;别</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="sex" value="1" title="男">
                                <input type="radio" name="sex" value="0" title="女" checked>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-date"></i> 日&nbsp;&nbsp;&nbsp;期</label>
                            <div class="layui-input-inline">
                                <input type="text" id="date" name="date" lay-verify="date" placeholder="yyyy-MM-dd"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><i
                                    class="layui-icon layui-icon-upload-circle"></i>上传头像</label>
                            <div class="layui-input-inline">
                                <input type="file" style="margin-top: 10px" name="file">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-key"></i>验证码</label>
                            <div class="layui-input-inline">
                                <input id="captcha" type="text" name="captchar" required lay-verify="required"
                                       placeholder="请输入验证码"
                                       autocomplete="off" class="layui-input">
                                <br>
                                <span id="msgcaptchar"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <img src="../kaptcha/render " style="width:180px;" id="cap">
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                <br>
                                <span id="msg"></span>
                            </div>
                        </div>

                    </form>
                </div>
            </div>

        </div>
    </div>
</div>

</body>
<script src="../layui/layui.js"></script>
<script>
    layui.use(function () {
        var layer = layui.layer
            , form = layui.form, laydate = layui.laydate;
        var $ = layui.$;
        //绑定日期
        laydate.render({
            elem: '#date'
        });

        //监听提交
        form.on('submit(formDemo)', function () {
            var formDate = new FormData(document.getElementById("form1"));
            $.ajax({
                url: '/customer/register',
                type: 'post',
                data: formDate,
                processData: false,
                contentType: false,
                success: function (ret) {
                    if (ret.code == 1) {
                        window.location = "/view/login.html";
                    } else {
                        layer.msg(ret.msg);

                    }
                }
            });
            return false;
        });


        $("#cap").click(function () {
            $(this).attr('src', "../kaptcha/render?" + new Date().getTime());
        });
        //校验用户名是否重复
        $("#username").mouseout(function () {
            var username = $(this).val();
            $.ajax({
                url: "/customer/chekcusername",
                type: "post",
                data: {
                    "username": username
                },
                success: function (ret) {
                    if (ret.code == -1) {
                        layer.msg(ret.msg)
                    }
                }
            })
        });

    });
</script>
</html>